<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
  <meta name="generator" content=
  "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org">

  <title>fill</title>
  <link href="../cppreference.css" rel="stylesheet" type="text/css">
</head>

<body>
<table>
  <tr>
  <td>
  <div class="body-content">

  <div class="header-box">
    <a href="../index.html">cppreference.com</a> &gt; <a href=
    "index.html">C++ Algorithms</a> &gt; <a href="fill.html">fill</a>
  </div>

  <div class="name-format">
    fill
  </div>

  <div class="syntax-name-format">
    Syntax:
  </div>
  <pre class="syntax-box">
  #include &lt;algorithm&gt;
  #include &lt;algorithm&gt;
  void fill( iterator start, iterator end, const <a href=
"../containers.html">TYPE</a>&amp; val );
</pre>

  <p>The function fill() assigns <em>val</em> to all of the elements
  between <em>start</em> and <em>end</em>.</p>

  <p>For example, the following code uses fill() to set all of the
  elements of a vector of integers to -1:</p>
  <pre class="example-code">
 vector&lt;int&gt; v1;
 for( int i = 0; i &lt; 10; i++ ) {
   v1.push_back( i );
 }              

 cout &lt;&lt; &quot;Before, v1 is: &quot;;
 for( unsigned int i = 0; i &lt; v1.size(); i++ ) {
   cout &lt;&lt; v1[i] &lt;&lt; &quot; &quot;;
 }
 cout &lt;&lt; endl;            

 fill( v1.begin(), v1.end(), -1 );              

 cout &lt;&lt; &quot;After, v1 is: &quot;;
 for( unsigned int i = 0; i &lt; v1.size(); i++ ) {
   cout &lt;&lt; v1[i] &lt;&lt; &quot; &quot;;
 }
 cout &lt;&lt; endl;            
</pre>

  <p>When run, the above code displays:</p>
  <pre class="example-code">
 Before, v1 is: 0 1 2 3 4 5 6 7 8 9
 After, v1 is: -1 -1 -1 -1 -1 -1 -1 -1 -1 -1            
</pre>

  <div class="related-name-format">
    Related topics:
  </div>

  <div class="related-content">
    <a href="fill_n.html">fill_n</a><br>
    <a href="generate.html">generate</a><br>
    <a href="transform.html">transform</a>
  </div>
  </div>
  </td>
  


  </tr>
  </table>
</body></html>
